/**
 * 
 */
package com.ms.service.module.fish;

import com.ms.game.slot.base.SlotGameBasicAction;
import com.ms.service.module.fish.game.GameConf;
import com.ms.service.module.zone.module.BasicZoneModule;
import com.xpec.c4.service.module.task.TaskTimer;

/**
 * 捕鱼遊戲 module
 * 
 * @author cuiwm
 */
public class FishGameModule extends BasicZoneModule {
	
	public static final int CHECK_VERIFY_TIME_OUT = 10 * 1000;
	
	public static final String GAME_TYPE = "FISH";

	/**
	 * 主要功能類別
	 */
	private FishProcessor proc = new FishProcessor();

	/**
	 * server 之間的連線是否完成
	 */
	private boolean serverConnectReady = false;

	/**
	 * 建構
	 */
	public FishGameModule() {
		super();
		setZone(proc);
	}

	@Override
	public void init() {
		super.init();
		registerActionClass(FishAction.class);
		
		registerActionClass(SlotGameBasicAction.class);
		
		// 初始化配置
		GameConf.init();
		
	}

	@Override
	public boolean startup() {
		// 每天扣除收益
		FishEveryDayTaskTimer taskTimer = new FishEveryDayTaskTimer();
		taskTimer.setCronExpressions("0 1 0 * * ? *"); // 每日0点1分执行
		this.addCronTaskTimer(taskTimer);
		
		// 检查保留座位到期
		FishClearSeatTaskTimer seatTaskTimer = new FishClearSeatTaskTimer();
		seatTaskTimer.setTimerOption(TaskTimer.LOOP);
		seatTaskTimer.setInitialDelay(CHECK_VERIFY_TIME_OUT);
		seatTaskTimer.setPeriod(CHECK_VERIFY_TIME_OUT);
		this.addTaskTimer(seatTaskTimer);
		
		return super.startup();
	}

	@Override
	public void onServerConnectReady() {
		super.onServerConnectReady();
		serverConnectReady = true;
		
	}

	@Override
	public void onUpdateTaskTimer(long periodTime) {
		super.onUpdateTaskTimer(periodTime);

		if (serverConnectReady) {
//			proc.onUpdate();
		}
	}

	public FishProcessor getProc() {
		return proc;
	}
}
